/**
 * 
 */
package edu.rit.cs.core.pojos;

import java.io.Serializable;

import javax.persistence.Column;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.validation.constraints.NotNull;

import org.apache.commons.codec.digest.DigestUtils;
import org.hibernate.validator.constraints.Length;

/**
 * A class representing the common information for the users of the system.
 * 
 * @author Abhishek Shrestha (axs1430)
 * @author Juan Saldana (jjs6109)
 * @author Victor Alvarez (vxa1557)
 */
@Entity
@Table(name = "users")
@DiscriminatorColumn(length = 20)
public abstract class AUser implements Serializable {
  private static final long serialVersionUID = 1L;

  private long id;
  private String username;
  private String password;

  /**
   * @return the id
   */
  @Id
  @GeneratedValue(strategy = GenerationType.AUTO)
  public long getId() {
    return id;
  }

  /**
   * @param id the id to set
   */
  public void setId(long id) {
    this.id = id;
  }

  /**
   * @return the username
   */
  @NotNull
  @Length(min = 6, max = 20)
  @Column(nullable = false, length = 20, unique = true)
  public String getUsername() {
    return username;
  }

  /**
   * @param username the username to set
   */
  public void setUsername(String username) {
    this.username = username;
  }

  /**
   * @return the password
   */
  @NotNull
  @Column(nullable = false, length = 40)
  public String getPassword() {
    return password;
  }

  /**
   * @param password the password to set
   */
  public void setPassword(String password) {
    this.password = password;
  }
  
  /**
   * @param password the password to set
   */
  @Transient
  public void setPlainPassword(String password) {
    this.password = DigestUtils.shaHex(password);
  }

  
}
